public class Remove {
    public static void main(String[] args) {
        int[] nums = new int[]{1,1,1};
        int len = removeDuplicates(nums);
        System.out.println(len);
    }
    public static int removeDuplicates(int[] nums) {
        int end = nums.length;
        for (int i = 0; i <= end-3;) {
            if(nums[i] == nums[i+2]) {
                //重复删除
                for (int j = i+2; j < end-1; j++) {
                    nums[j] = nums[j+1];
                }
                end--;
            }else {
                i++;
            }
        }
        return end;
    }
}
